
const http=require('../../utils/http');

Page({
      data: {
            detail:{},
            query:{
                  channel:0,
                  activityId:'',
                  mobile:''
            }
      },
      // activityAddress: "兴盛大道加油站斜对面"
      // activityContact: "13507991209"
      // activityDate: "2020-12-08 00:00:00"
      // activityId: 21
      // activityTitle: "正兴跆拳道寒假开班了"
      // bizPayNo: null
      // createTime: "2021-01-21T17:16:36"
      // fee: "0.01"
      // id: 21
      // mobile: "13907495924"
      // payCode: "1352183309236572160"
      // status: null
      // txt: "已支付"
      // userId: 27
      // userName: "Rainie。"
      onLoad: function (options) {
            wx.getStorage({
                  key:'activity',
                  success:(res)=> {
                        console.log(res,'res---')
                        this.setData({
                              detail:res.data
                        })

                  }
            })
      },
      getMobile(e) {
            this.setData({
                 "query.mobile":e.detail.value
            })
      },
      wxPay(data){
            let that=this;
            wx.requestPayment({
                  timeStamp: data.timeStamp,
                  nonceStr: data.nonceStr,
                  package: data.packageValue,
                  paySign: data.paySign,
                  signType: data.signType,
                  success:(res)=> {
                        wx.switchTab({
                              url: '/pages/user/user',
                              success(res) {
                                    wx.showToast({

                                          title: '报名成功'
                                    })
                              }
                        })
                  }
            })
      },
      goPay(){
            let that=this;
            let reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/
            if (!this.data.query.mobile) {
                  wx.showModal({
                        title: '提示',
                        showCancel:false,
                        content: "请输入您的联系方式"
                  })
            }else if(!reg.test(this.data.query.mobile)){

                  wx.showModal({
                        title: '提示',
                        showCancel:false,
                        content: "手机号格式不正确"
                  })
            }else{

                  this.data.query.activityId=this.data.detail.id
                  wx.showModal({
                        title:'提示',
                        content:"确定报名参加此次活动吗",
                        success:(res)=> {
                              if(res.confirm){
                                    http.request({
                                          url:'/activitiOrder/payOrder',
                                          data:this.data.query,
                                          callBack:(res)=>{
                                                console.log(res,'res---')
                                                if(res.code==200){
                                                      this.wxPay(res.data);
                                                }
                                          }
                                    })
                              }
                        }
                  })
            }

      },
});